package com.genius.adminmanager.menu.controller;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.genius.adminmanager.menu.service.MenuService;
import com.genius.adminmanager.other.entity.ResponseJson;
import com.genius.workflow.config.DefaultConfiguration;
import com.genius.workflow.ehcache.CacheUtils;

@Controller
public class MenuTreeSelectController {

	@GetMapping("/adminmanager/menu/queryTreeList")
	@ResponseBody
	public JSONObject queryTreeList(){
		JSONObject response = new JSONObject();
    	response.put(ResponseJson.code, 0);
    	
    	JSONArray root = (JSONArray)CacheUtils.cacheUtils().getElement(DefaultConfiguration.menuRAM, DefaultConfiguration.menuRAM_tree);
    	if(root == null){
    		MenuService.loadMenusRAM();
    		root = (JSONArray)CacheUtils.cacheUtils().getElement(DefaultConfiguration.menuRAM, DefaultConfiguration.menuRAM_tree);
    	}
    	response.put(ResponseJson.status, ResponseJson.status_Success);
		response.put(ResponseJson.data, root);
    	return response;
	}
}
